package cn.bgs.controller;


import cn.bgs.service.ToupService;
import cn.bgs.utils.R;
import cn.bgs.vo.Pagevo;
import cn.bgs.vo.TopUpvo;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/controller")
public class ToupController {
    @Resource
    ToupService toupService;
    //住户标签页面全查
    @PostMapping ("/toup")
    public PageInfo<TopUpvo> selectAll(@RequestBody Pagevo pagevo){
        PageInfo<TopUpvo> page =toupService.page2(pagevo);
        return page;
    }
    //住户标签页面删除
    @DeleteMapping("/{topUpId}")
    public R delete(@PathVariable Integer topUpId){
        System.out.println(topUpId);
        toupService.delete(topUpId);
            if(topUpId !=null){
                return R.ok().data("删除成功",topUpId);
            }else{
                return R.error();
            }


    }
    //住户标签页面修改
    @PostMapping("/update")
    public R update(@RequestBody TopUpvo form){
        toupService.updateTop(form);
//        if(form.userId!=null){
//            return R.ok().data("修改成功",userId);
//        }else{
//            return R.error();
//        }
        return R.ok();
    }
    //住户标签页面添加
    @PostMapping("/insertAll")
    public R insertAll(@RequestBody TopUpvo insertaa){
        toupService.insertAll(insertaa);
        return R.ok();
    }
}
